<template>
  <div class="containsClass">
    <div class="bodyClass">
      <div>
        <img
          class="backClass"
          @click="goBack"
          src="@/assets/login/fanhui.svg"
        />
        <div class="titleClass">{{ classData.className }}</div>

        <div class="boxClass">
          <div class="tableTitClass">
            <div class="numberClass">序号</div>
            <div class="nameClass">姓名</div>
            <!-- <div class="borClass">是否佩戴眼镜</div> -->
            <div>是否测试</div>
          </div>
          <div class="dataBoxClass">
            <div class="noInfo" v-if="dataList.length === 0">暂无数据</div>
            <div v-for="(item, key) in dataList" :key="key">
              <div class="numberClass">{{ item.index }}</div>
              <div class="nameClass">{{ item.nickName }}</div>
              <!-- <div>
                <a-switch v-model="item.status" />
              </div> -->
              <div>
                <a-switch v-model="item.isTest" />
              </div>
            </div>
          </div>
        </div>
        <a-button shape="round" @click="goPage" class="btnClass"
          >开始测试</a-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import { notification } from "ant-design-vue";
import screenfull from "screenfull";
export default {
  data() {
    return {
      dataList: [
        // {
        //   name: "陈小小",
        //   number: 20240103126,
        //   status: true,
        // },
      ],
      classData: JSON.parse(sessionStorage.getItem("classData")),
    };
  },
  created() {
    this.$store.commit("setIsShow", false);
    let userInfo = JSON.parse(sessionStorage.getItem("myUserInfo"));
    let params = {
      teacherId: userInfo.id,
      loginKey: userInfo.loginKey,
      uid: userInfo.uid,
      page: 1,
      childCountPerPage: 1000,
      classId: this.classData.classId,
    };
    this.$POST("/pad/getChildList", params).then((rr) => {
      console.log("rr", rr);
      this.dataList = rr.data?.childrenList;
      /* let list = rr.data?.childrenList;
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list);
      this.dataList.push(...list); */
      this.dataList.forEach((i, index) => {
        this.$set(i, "isTest", true);
        if (index == 0) {
          this.$set(i, "currentStatus", 1); //1正在测试 2请准备 3等待 4不测试 5已测试 6已跳过
        } else if (index == 1) {
          this.$set(i, "currentStatus", 2);
        } else {
          this.$set(i, "currentStatus", 3);
        }
      });
    });
  },
  methods: {
    goBack() {
      this.$router.go(-1);
    },
    goPage() {
      if (this.dataList.length === 0) {
        return notification.error({
          message: "提示",
          description: "该班级暂无学生，请选择其他班级",
        });
      }
      sessionStorage.setItem("childrenList", JSON.stringify(this.dataList));
      let list = this.dataList.filter((i) => i.isTest);
      /*  list.forEach(i=>{
        i.status = 0
      }) */
      if (list.length == 0) {
        return notification.error({
          message: "提示",
          description: "请选择学生后再进行测试",
        });
      }
      this.$store.commit("setChildList", list);
      this.$store.commit("setIsShow", true);

      let data = {};
      this.$set(data, "distance", 5); // 米
      this.$store.commit("setTestingData", data);

      if (screenfull.isEnabled) {
        screenfull.request();
      } else {
        console.warn("全屏功能未启用，可能是因为浏览器不支持或用户未授予权限");
      }
      sessionStorage.setItem("nowEye", "left");
      this.$router.push("/ChooseEye");
    },
  },
};
</script>

<style lang="less" scoped>
.containsClass {
  width: 30vw;
  height: 100%;
  .bodyClass {
    width: 100%;
    height: 100%;
    background-size: cover; /* 图片覆盖整个容器 */
    background-repeat: no-repeat; /* 防止图片重复 */
    background-position: center; /* 图片居中显示 */
    background-image: url("~@/assets/login/beijingtu_a.png");
    margin: 0 auto;
    padding-top: 0.2rem;
    text-align: center;
    font-weight: bold;
    position: relative;
    & > div {
      width: 90%;
      height: 100%;
      margin: 0 auto;
      position: relative;
      .backClass {
        position: absolute;
        cursor: pointer;
        left: 0;
        top: 0;
        width: 0.25rem;
        height: 0.25rem;
      }
      .titleClass {
        font-size: 0.16rem;
        color: #0f6c80;
        margin-bottom: 0.15rem;
      }
      .boxClass {
        height: 70%;
        margin: 0 auto;
        background-color: #fff;
        border-radius: 0.06rem;
        .tableTitClass {
          height: 0.2rem;
          line-height: 0.2rem;
          display: flex;
          div {
            padding: 0.05rem 0;
            flex: 3;
            font-size: 0.1rem;
            color: #adabab;
          }
          .numberClass {
            border-right: 0.01rem solid rgba(173, 171, 171, 0.2);
          }
          .nameClass {
            flex: 3;
            border-right: 0.01rem solid rgba(173, 171, 171, 0.2);
          }
          .borClass {
            border-right: 0.01rem solid rgba(173, 171, 171, 0.2);
          }
        }
        .dataBoxClass {
          height: calc(100% - 0.2rem);
          overflow-y: auto;
          .noInfo {
            display: flex;
            height: 100%;
            align-items: center;
            justify-content: center;
            font-size: 0.16rem;
            color: #adabab;
          }
          & > div {
            display: flex;
            padding: 0.05rem;
            div {
              padding: 0.05rem 0;
              flex: 3;
              font-size: 0.1rem;
              color: #adabab;
            }
            .nameClass {
              flex: 3;
              white-space: nowrap;
              /* 确保文本在一行内显示 */
              overflow: hidden;
              /* 隐藏超出容器的内容 */
              text-overflow: ellipsis;
              /* 使用省略符号表示被截断的文本 */
            }
          }
        }
      }
      .btnClass {
        width: 55%;
        height: 0.3rem;
        font-size: 0.12rem;
        letter-spacing: 0.03rem;
        text-indent: 0.03rem;
        color: #fff;
        background-color: #ffa574;
        margin-top: 0.25rem;
      }
    }
  }
}
</style>